package com.example.detectivedemo.domain.player;

import java.io.Serializable;

/**
 * 玩家领域模型
 * 定义玩家的核心属性和行为
 */
public class Player implements Serializable {
    private static final long serialVersionUID = 1L;
    
    private String playerId;
    private String username;
    private String nickname;
    private String avatar;
    private int level;
    private int experience;
    private int solvedCases;
    private int totalScore;
    private boolean isLogin;
    
    // 构造函数
    public Player() {
    }
    
    public Player(String playerId, String username, String nickname) {
        this.playerId = playerId;
        this.username = username;
        this.nickname = nickname;
        this.level = 1;
        this.experience = 0;
        this.solvedCases = 0;
        this.totalScore = 0;
        this.isLogin = false;
    }
    
    // Getter和Setter方法
    public String getPlayerId() {
        return playerId;
    }
    
    public void setPlayerId(String playerId) {
        this.playerId = playerId;
    }
    
    public String getUsername() {
        return username;
    }
    
    public void setUsername(String username) {
        this.username = username;
    }
    
    public String getNickname() {
        return nickname;
    }
    
    public void setNickname(String nickname) {
        this.nickname = nickname;
    }
    
    public String getAvatar() {
        return avatar;
    }
    
    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }
    
    public int getLevel() {
        return level;
    }
    
    public void setLevel(int level) {
        this.level = level;
    }
    
    public int getExperience() {
        return experience;
    }
    
    public void setExperience(int experience) {
        this.experience = experience;
        // 自动升级逻辑
        checkLevelUp();
    }
    
    public int getSolvedCases() {
        return solvedCases;
    }
    
    public void setSolvedCases(int solvedCases) {
        this.solvedCases = solvedCases;
    }
    
    public int getTotalScore() {
        return totalScore;
    }
    
    public void setTotalScore(int totalScore) {
        this.totalScore = totalScore;
    }
    
    public boolean isLogin() {
        return isLogin;
    }
    
    public void setLogin(boolean login) {
        isLogin = login;
    }
    
    // 业务方法：增加经验值
    public void addExperience(int exp) {
        this.experience += exp;
        checkLevelUp();
    }
    
    // 业务方法：增加解决案件数
    public void addSolvedCase(int score) {
        this.solvedCases++;
        this.totalScore += score;
    }
    
    // 业务方法：检查升级
    private void checkLevelUp() {
        // 简单的升级规则：每100经验升一级
        int newLevel = (this.experience / 100) + 1;
        if (newLevel > this.level) {
            this.level = newLevel;
            // 可以添加升级事件通知
        }
    }
    
    @Override
    public String toString() {
        return "Player{" +
                "playerId='" + playerId + '\'' +
                ", username='" + username + '\'' +
                ", nickname='" + nickname + '\'' +
                ", level=" + level +
                ", experience=" + experience +
                ", solvedCases=" + solvedCases +
                ", totalScore=" + totalScore +
                ", isLogin=" + isLogin +
                '}';
    }
}